<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1">
		<!-- Google Chrome Frame也可以让IE用上Chrome的引擎: -->
		<meta name="renderer" content="webkit">
		<!--国产浏览器高速模式-->
		<meta name="viewport" content="width=device-width, initial-scale=1">

		<title>电力通信后台管理系统</title>

		<!-- 公共样式 开始 -->
		<link rel="stylesheet" type="text/css" href="../css/base.css">
		<link rel="stylesheet" type="text/css" href="../css/iconfont.css">
		<script type="text/javascript" src="../framework/jquery-1.11.3.min.js"></script>
		<link rel="stylesheet" type="text/css" href="../layui/css/layui.css">
		<script type="text/javascript" src="../layui/layui.js"></script>
		<!-- 滚动条插件 -->
		<link rel="stylesheet" type="text/css" href="../css/jquery.mCustomScrollbar.css">
		<script src="../framework/jquery-ui-1.10.4.min.js"></script>
		<script src="../framework/jquery.mousewheel.min.js"></script>
		<script src="../framework/jquery.mCustomScrollbar.min.js"></script>
		<script src="../framework/cframe.js"></script><!-- 仅供所有子页面使用 -->
		<!-- 公共样式 结束 -->

	</head>

	<body>
		<div class="cBody">
			<form id="addForm" class="layui-form" action="">
				<div class="layui-form-item">
					<label class="layui-form-label">原始密码</label>
					<div class="layui-input-inline shortInput">
						<input type="password" name="manpassword" placeholder="请输入原密码" required lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">新密码</label>
					<div class="layui-input-inline shortInput">
						<input type="password" name="newPassWord" placeholder="请输入新密码" required lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">确认新密码</label>
					<div class="layui-input-inline shortInput">
						<input type="password" name="password2" placeholder="请再次输入新密码" required lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>

				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn" lay-submit lay-filter="submitBut">确认修改</button>
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
				</div>
			</form>

			<script>
				layui.use('form', function() {
					var form = layui.form;
					//监听提交
					form.on('submit(submitBut)', function(data) {
						var user=JSON.parse(window.sessionStorage.getItem("user"));
						var body=data.field
						body.id=user.id;
						body.managerid=user.managerid;
						if(body.newPassWord!==body.password2){
							layer.msg("两次密码不一致");
							return false;
						}
						if(body.newPassWord===body.manpassword){
							layer.msg("新密码与旧密码一致，请重新设置");
							return false;
						}
						$.ajax({
							xhrFields: {
								withCredentials: true
							},
							crossDomain: true,
							type: "post",
							// dataType: "json",
							url: "http://localhost:8888/user/updatePassword",
							data:JSON.stringify(body),
							contentType: "application/json;charset=UTF-8",//指定消息请求类型
							success: function (data) {
								if (data.code == 0) {
									layer.msg("修改成功，请重新登录")
									window.sessionStorage.removeItem("user");
									setTimeout(function () {
										window.location.assign("../login.html")
									},1000)
								} else {
									layer.msg(data.msg)
								}
							}
						})
						return false;
					});

				});
			</script>

		</div>
	</body>

</html>
